/**
 * 修改业务数据弹出框
 */
import { Button, Input, Form, Modal, Select } from "antd";
import { forwardRef, useImperativeHandle, useState, useRef, useLayoutEffect, useEffect } from "react";
import request from "../../framework/common/utils/request";
import { useForm } from "../../framework/common/context/metadata-context";
import { message } from "antd";
import { getQuery } from "../../framework/common/utils";
import md5 from "js-md5";
import { globalModule } from "../../approval/index.js";
import eventBus, { useSubscribe } from "../../framework/common/eventBus";
const { TextArea } = Input;

export default function ModalDataChange ({

}) {
  const { data: tplData, urlPrefix, params } = useForm().root;
  const [modalConfig, setModalConfig] = useState({
    modalShow: false
  });
  
  useSubscribe("modalDataChange.update", (data)=>{

    //弹框销毁后事件，只需要初次显示弹框时绑定一次，不需要每次调用都绑定，所以这样判断缓存一下
    if(modalConfig.afterClose && !data.afterClose){
      data.afterClose = modalConfig.afterClose;
    }

    setModalConfig(data);
  },[modalConfig.modalShow])//更新弹出框信息

  return <>
            <Modal
              centered={true}
              title={modalConfig.title}
              width="94%"
              visible={modalConfig.modalShow}
              footer={null}
              destroyOnClose={true}
              onCancel={()=>{
                setModalConfig({
                  modalShow: false
                });//隐藏模态框
                modalConfig?.afterClose?.();//关闭弹框时，执行业务数据同步
              }}
              afterClose={()=>{
                modalConfig?.afterClose?.();//关闭弹框时，执行业务数据同步
              }}
            >
              <div className="pb-6" style={{ height: "80vh" }}>
                <iframe 
                  width="100%"
                  height="100%"
                  src={modalConfig.url}
                ></iframe>
              </div>
            </Modal>
          </>;
};